import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

def stream_plot_3d():
    # 1. Define your 2D vector field (e.g., a projection of a 3D field)
    x_2d = np.linspace(-3, 3, 50)
    y_2d = np.linspace(-3, 3, 50)
    X_2d, Y_2d = np.meshgrid(x_2d, y_2d)
    U_2d = -Y_2d
    V_2d = X_2d

    # 2. Generate 2D streamlines and extract paths
    fig_temp, ax_temp = plt.subplots()
    strm = ax_temp.streamplot(X_2d, Y_2d, U_2d, V_2d, color='blue', linewidth=0.8)
    plt.close(fig_temp)  # Close the temporary 2D figure

    lines = strm.lines.get_paths()

    # 3. Create a 3D figure and axes
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')

    # 4. Apply transformation and plot in 3D
    for line in lines:
        x_coords = line.vertices.T[0]
        y_coords = line.vertices.T[1]

        # Example transformation: z is a function of x and y
        z_coords = np.sin(np.sqrt(x_coords ** 2 + y_coords ** 2))

        ax.plot(x_coords, y_coords, z_coords, color='blue', linewidth=0.8)

    # Set labels and title for the 3D plot
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    ax.set_title('3D Streamplot (Projected from 2D)')

    plt.show()